fdim
From cppreference.com
| Defined in header <math.h>
|
||
| float fdimf( float x, float y ); |
(since C99) | |
| double fdim( double x, double y ); |
(since C99) | |
| long double fdiml( long double x, long double y ); |
(since C99) | |
Returns the positive difference between x and y. This could be implemented as fmax (x - y, 0), so if x ≤ y, the result is always equals to 0, otherwise it is x - y.
Contents |
[edit] Parameters
| x, y | - | floating point value |
[edit] Return value
The positive difference value.
[edit] Example
Run this code
#include <stdio.h> #include <math.h> #include <errno.h> int main() { printf ("fdim(4.0,1.0) = %.1f\n", fdim(4.0,1.0)); printf ("fdim(1.0,4.0) = %.1f\n", fdim(1.0,4.0)); printf ("fdim(NAN,1.0) = %.1f\n", fdim(NAN,1.0)); printf ("fdim(1.0,INFINITY) = %.1f\n", fdim(1.0,INFINITY)); /* range error */ errno = 0; printf ("fdim(INFINITY,1.0) = %.1f\n", fdim(INFINITY,1.0)); printf("errno = %d\n", errno); return 0; }
Possible output:
fdim(4.0,1.0) = 3.0 fdim(1.0,4.0) = 0.0 fdim(NAN,1.0) = nan fdim(1.0,INFINITY) = 0.0 fdim(INFINITY,1.0) = inf errno = 34
[edit] See also
| (C99) |
computes absolute value of an integral value (|x|) (function) |
| (C99) |
larger of two floating point values (function) |
| C++ documentation for fdim
| |